function thetaReturned = NXTRotate(theta)
power = 50;
frictionFactor = 1.1;

%Gets around tacholimit=0 motors running indefinitely issue.
if theta == 0
    thetaReturned = 0;
    return
end
theta = theta * 180/pi;
OpenSwitch(SENSOR_4)

% COM_CloseNXT all
% h = COM_OpenNXT();
% COM_SetDefaultNXT(h);
% OpenUltrasonic(SENSOR_1);
if theta < 0
    power = -power;
    theta = -theta;
end
tacholimit = round((11.8/4.4)*theta*frictionFactor);
if tacholimit == 0
    thetaReturned = 0;
    return
end
mA = NXTMotor('A', 'Power', power, 'TachoLimit',tacholimit);
mB = NXTMotor('C', 'Power', -power, 'TachoLimit',tacholimit);
mA.SendToNXT();
mB.SendToNXT();
Z = mA.ReadFromNXT.TachoCount;
Z2 = 100;
x = GetSwitch(SENSOR_4);
while (((abs(Z) < 1) | (abs(Z2) < 1)) | (Z ~= Z2)) & (x == 0)
    Z2 = Z;
    Z = mA.ReadFromNXT.TachoCount;
    pause(0.01)
    x = GetSwitch(SENSOR_4);
end
mA.Stop('brake')
mB.Stop('brake')
thetaReturned = theta*mA.ReadFromNXT.TachoCount/tacholimit;
thetaReturned = thetaReturned*pi/180;